package com.zjf.fupload.popup.actions;

import java.util.LinkedList;

import com.zjf.fupload.FUploadPlugin;

/**
 * @author zjf
 */
public class RecentPathList {
	
	private int size = 20;
	
	public RecentPathList(int size) {
		this.size = size;
	}
	
	public RecentPathList() {
	}

	private LinkedList<String> recentList = 
		new LinkedList<String>();
	
	public void add(String path) {
		recentList.remove(path);
		recentList.push(path);
		if(recentList.size() > this.size) {
			recentList.pollLast();
		}
	}
	
	public String[] array() {
		
		return recentList.toArray(new String[] {});
		
	}
	
	public String toString() {
		String result = "";
		String[] array = array();
		for(String s : array) {
			result += s + FUploadPlugin.PREFERENCE_DELIMITER;
		}
		
		if(result.length() > 0) {
			result = result.substring(0, result.length() - 1);
		}
		
		return result;
		
		
	}
	
	public static RecentPathList parse(String paths) {
		
		RecentPathList list = new  RecentPathList();
		String[] array = paths.split(FUploadPlugin.PREFERENCE_DELIMITER);
		for(String path : array) {
			if(path.length() > 0) {
				list.add(path);
			}
		}
		
		return list;
		
	}
	
}
